<?php 
	session_start();
error_reporting(E_ALL && ~E_NOTICE);
?>
<style  type="text/css">
.li_level{
	background:#E3F2EA;
}
</style>
<script type="text/javascript">
	$("li.li_level").bind('click',function(){
		var id=$(this).attr('id');	
		var point=$(this).attr('point');
		//alert('id'+id+' point='+point);
		$('input#'+id).attr('value',point);
		/*var vl=$('input#'+id).attr('value');
		alert(vl);*/
		$(this).css({"backgroundColor":"#06F","color":"white"});
		$(this).prevAll().css({"backgroundColor":"#06F","color":"green"});
		
		$(this).nextAll().css({"backgroundColor":"#E3F2EA","color":"green"});
		
	});
	
	$('.chk_ans').bind('click',function(){
		if($(this).is(':checked')){
			//alert('sd');
			$(this).parent().siblings().each(function(){
				$(this).find('.chk_ans').prop('checked', false)
			});
		}
	});
	
	$("form.reans_frm").on('submit',function(event){
		event.preventDefault();
		var $this=$(this);
		var $btn=$("#btn_submit");
		var iduser=$btn.attr('user');
		var idquest=$btn.attr('quest');
		
		//alert($iduser);
		var kind=$btn.attr("kind");//alert(kind);
		//$(this).find(".chk_ans:not(:checked)").prop('checked', false);
		$('.chk_ans').each(function(){
			if(!($(this).is(':checked'))){
				/*var id =$(this).attr('id');
				alert(id);*/
				$(this).parent().remove();//.prop('checked', false);
			}
		});
		
		if(kind=='Answer'){
			url='web/member/new_answer.php';
			$.ajax({
				type:'get',
				url:url,
				data:$this.serialize(),
				success:function(result){
					alert(result);
					$("div.pLeft").hide().load('web/member/new_question.php').show('slow');
				}
			});
			
		}else{
			url='web/member/re_answer.php';
			$.ajax({
				type:'get',
				url:url,
				data:$this.serialize(),
				success:function(result){
					//alert(result);
					$("div.pLeft").hide().load('web/member/question.php').show('slow');
				}
			});
		}
		$.ajax({
			type:'get',
			url:'web/function/match.php',
			data:'iduser='+iduser+'&idquest='+idquest,
			success:function(result){
				alert(result);
				$("#h_match").load('web/member/hightestmatch.php?iduser='+iduser);
			}
		});
		return false;
	});
	
	$(".skip").bind('click',function(){
		$(this).parents('div.new_ans').css({}).slideUp('slow');
		$('.answer').show();
		$(this).parents().siblings('a.re_ans').show();
		return false;
	});
	
</script>
<?php 
include '../../db/dbConnect.php';
$idq=mysql_real_escape_string($_GET['idquest']);
$kind=mysql_real_escape_string($_GET['kind']);
if($_SERVER['REQUEST_METHOD']=="GET" && ($_GET["user_profile"])){
		$user=$_GET["user_profile"];
}else {
	//unset($user);
	$user=$_SESSION['LoginData']['iduser'];
}
?>
<div class="reans">
<h3 class="guide_ans">Trả lời</h3>
<form id="asn_frm_<?php echo $idq?>" class="reans_frm" method="get" action="">
<input name="idquestion" type="text" value="<?php echo $idq;?>" style="display:none" />
<?php 
if($_SERVER['REQUEST_METHOD']=="GET"){
	
	$sql='select * from u_profile_answer where idquestion="'.$idq.'"';
	$result=mysql_query($sql);
	echo mysql_error();
	while($row=mysql_fetch_array($result)){	?>
		<label for="chk<?php echo $row['idpr_answer'];?>">
        	<input id="chk<?php echo $row['idpr_answer'];?>" name="idanswer" class="chk_ans" type="checkbox" value="<?php echo $row['idpr_answer'];?>" />&nbsp;<?php echo $row['answer'];?>
        </label>	
	<?php
	}?> 
    <textarea id="re_exp" name="re_exp" placeholder="Explain" style="display:none" ></textarea>
    <input id="<?php echo $idq ?>" name="level" type="text" value="" style="display:none" />
    <h3 class="guide_ans">Bạn qua tâm đến câu hỏi này như thế nào?</h3>
    <ul class="ul_level">
    	<li class="li_level" point="5" id="<?php echo $idq;?>">không quan trọng</li>
        <li class="li_level" point="10" id="<?php echo $idq;?>">khá quan trọng</li>
        <li class="li_level" point="20" id="<?php echo $idq;?>">rất quan trọng</li>
    </ul>
    <br />
   <div class="div_submit"><input type="submit" name="submit" class="" id="btn_submit" kind="<?php if($kind && $kind=="new_ans"){ echo 'Answer';}?>" value="<?php if($kind){if($kind=="new_ans"){ echo 'Trả lời';}elseif($kind=="re_ans") echo 'Trả lời'; }?>" user="<?php echo $user;?>" quest="<?php echo $idq; ?>" />
   <input type="button" name="skip" id="btn_submit" class="skip" value="Hủy" /></div>
   
	<?php 	
}
?>
</form></div>
